<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    function rebuy () {
      console.log("开始买笔");
      var p = new Promise(function (resolve, reject) {
        setTimeout(function () {
          // console.log("买笔失败");
          // reject("没带够钱");
          console.log("购买笔成功");
          resolve("购买笔成功")

        }, 1000);
      });
      return p;
    }

    function rework (data) {
      console.log("开始写作业：" + data);
      var p = new Promise(function (resolve, reject) {
        setTimeout(function () {
          console.log("写完作业");
          resolve("作业本");
        }, 1000);
      });
      return p;
    }

    rebuy().then(rework).catch(err => {
      console.log(err, "没有笔,不能写作业");

    })
  </script>
</body>

</html>